package cc.realxyq.demo.config;

import cc.realxyq.demo.bean.Person;
import cc.realxyq.demo.bean.Teacher;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Scope;

/**
 * scope作用域的配置，以及自定义scope的使用
 * @author kwhan
 * @date 2022年01月07日 12:04
 */
@Slf4j
@Configuration
public class ScopeTypeConfig {

    @Scope(value = ConfigurableBeanFactory.SCOPE_SINGLETON)
    @Lazy
    @Bean
    public Teacher teacher01(){
        log.info("初始化teacher");
        return  new Teacher("kwhan" , 22);
    }

    @Bean
    @Scope(value = "threadScope")
    public Person person(){
        log.warn("注入自定义scope的bean对象：对象的{}",this.getClass().getName());
        return new Person("lisi",22);
    }
}
